home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBASE102.ARJ / BSETBUF.C < prev    next >
Text File  |  1991-09-23  |  2KB  |  85 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)bsetbuf.c    1.5 - 91/09/23" */
  5.  
  6. #include <ansi.h>
  7.  
  8. /* ansi headers */
  9. #include <errno.h>
  10. #ifdef AC_STDDEF
  11. #include <stddef.h>
  12. #endif
  13.  
  14. /* local headers */
  15. #include "blkio_.h"
  16.  
  17. /*man---------------------------------------------------------------------------
  18. NAME
  19.      bsetbuf - assign buffering to a block file
  20.  
  21. SYNOPSIS
  22.      #include <blkio.h>
  23.  
  24.      int bsetbuf(bp, buf)
  25.      BLKFILE *bp;
  26.      void *buf;
  27.  
  28. DESCRIPTION
  29.      The bsetbuf function causes the storage area pointed to by buf to
  30.      be used by the block file associated with BLKFILE pointer bp
  31.      instead of an automatically allocated buffer area.  If buf is the
  32.      NULL pointer, bp will be completely unbuffered.  Otherwise, it
  33.      must point to a storage area of size no less than
  34.  
  35.           header size + block size * buffer count
  36.  
  37.      bsetbuf may be called at any time after opening the block file,
  38.      before and after it is read or written; the buffers are flushed
  39.      before installing the new buffer area.
  40.  
  41.      bsetbuf will fail if one or more of the following is true:
  42.  
  43.      [EINVAL]       bp is not a valid BLKFILE pointer.
  44.      [BENBUF]       bp is unbuffered and buf is not the NULL
  45.                     pointer.
  46.      [BENOPEN]      bp is not open.
  47.  
  48. SEE ALSO
  49.      bopen, bsetvbuf.
  50.  
  51. DIAGNOSTICS
  52.      Upon successful completion, a value of 0 is returned.  Otherwise,
  53.      a value of -1 is returned, and errno set to indicate the error.
  54.  
  55. NOTES
  56.      A common source of error is allocating buffer space as an
  57.      automatic variable in a code block, and then failing to close the
  58.      block file in the same block.
  59.  
  60. ------------------------------------------------------------------------------*/
  61. #ifdef AC_PROTO
  62. int bsetbuf(BLKFILE *bp, void *buf)
  63. #else
  64. int bsetbuf(bp, buf)
  65. BLKFILE *bp;
  66. void *buf;
  67. #endif
  68. {
  69.     /* validate arguments */
  70.     if (!b_valid(bp)) {
  71.         errno = EINVAL;
  72.         return -1;
  73.     }
  74.     if ((bp->bufcnt == 0) && (buf != NULL)) {
  75.         errno = BENBUF;
  76.         return -1;
  77.     }
  78.  
  79.     if (buf == NULL) {
  80.         return bsetvbuf(bp, buf, bp->blksize, (size_t)0);
  81.     }
  82.  
  83.     return bsetvbuf(bp, buf, bp->blksize, bp->bufcnt);
  84. }
  85.